package com.example.springboottest.example.rabbitmq;

import com.rabbitmq.client.ConnectionFactory;

import java.net.URISyntaxException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;

public class RabbitUtil {
    public static ConnectionFactory getConnectionFactory() {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("localhost");
        factory.setPort(5672);
        factory.setUsername("rabbit");
        factory.setPassword("rabbit");
        factory.setVirtualHost("/");
        return factory;
    }

    public static ConnectionFactory getConnectionFactoryV2() {
        ConnectionFactory factory = new ConnectionFactory();
        try {
//            factory.setUri("amqp://userName : password@ipAddress:portNumber/virtualHost");
            factory.setUri("amqp://rabbit:rabbit@localhost:5672");
        } catch (URISyntaxException e) {
            e.printStackTrace();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (KeyManagementException e) {
            e.printStackTrace();
        }
        return factory;
    }
}
